package com.example.demo.config;


import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@PropertySource(value = {"classpath:/Swagger2.properties"}, encoding = "utf-8")
@EnableSwagger2WebMvc
@Configuration
@EnableKnife4j
public class Swagger2Config {
    @Value("${nature.restApi.enabled}")
    private Boolean enable;

    @Value("${application.name}")
    private String applicationName;

    @Value("${application.version}")
    private String applicationVersion;

    @Value("${application.description}")
    private String applicationDescription;

    @Value("${application.group01}")
    private String applicationGroup01;

    @Value("${application.apis.selector01}")
    private String selector01;
    @Value("${application.group02}")
    private String applicationGroup02;
    @Value("${application.description1}")
    private String description1;

    @Value("${application.apis.selector02}")
    private String selector02;

    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(enable)
                .groupName(applicationGroup01)
                .select()
                .apis(RequestHandlerSelectors.basePackage(selector01))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean
    public Docket docket1() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo1())
                .enable(enable)
                .groupName(applicationGroup02)
                .select()
                .apis(RequestHandlerSelectors.basePackage(selector02))
                .paths(PathSelectors.any())
                .build();
    }


    @Bean
    ApiInfo apiInfo1() {
        return new ApiInfoBuilder()
                .title(applicationName)
                .description(description1)
                .version(applicationVersion)
                .build();
    }

    @Bean
    ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(applicationName)
                .description(applicationDescription)
                .version(applicationVersion)

                .build();
    }

    public String getDescription1() {
        return description1;
    }

    public void setDescription1(String description1) {
        this.description1 = description1;
    }
}
